<?php

Class progress_model extends CI_Model {

    public function __construct() {
        $this->load->database();
    }
    
    public function getColorLevel($level){
        $query = $this->db->get_where('level', array('level_number' => $level));
        return $query->row_array();
    }

    public function insertProgress($data) {
        $this->db->set('date', 'curdate()', FALSE);
        $this->db->insert('progress', $data);
        return;
    }

    public function getStudentProfile($userid) {
        $query = $this->db->get_where('student_profile', array('user_id' => $userid));
        return $query->row_array();
    }

    public function getStoryDetails($storyid) {
        $query = $this->db->get_where('story', array('story_id' => $storyid));
        return $query->row_array();
    }

    public function updateStudent($id, $data) {
        $query = $this->db->where('user_id', $id);
        $query = $this->db->update('student_profile', $data);
        return $query;
    }

    public function updateStatus($param, $data) {
        $id = $param['user_id'];
        $criteria = $param['criteria_id'];
        $query = $this->db->where('criteria_id', $criteria);
        $query = $this->db->where('user_id', $id);
        $query = $this->db->update('status', $data);
        return $query;
    }

    public function refreshStatus($userid, $data, $criteria = '') {

        if (empty($criteria)) {
            $query = $this->db->where('user_id', $userid);
            $query = $this->db->update('status', $data);
        } else if (!empty($criteria)) {
            $query = $this->db->where('user_id', $userid);
            $query = $this->db->where_in('criteria_id', $criteria);
            $query = $this->db->update('status', $data);
        }
        return $query;
    }

}

?>
